package com.experiment.experiment_big.controller;

import com.tencentcloudapi.captcha.v20190722.CaptchaClient;
import com.tencentcloudapi.captcha.v20190722.models.DescribeCaptchaResultRequest;
import com.tencentcloudapi.captcha.v20190722.models.DescribeCaptchaResultResponse;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Save_verification {
    /**
     * 腾讯防水墙
     * @param ticket
     * @param randstr
     * @param userip
     * @return
     */
    @RequestMapping("/verification")
    public String verification(String ticket,String randstr,String userip){

        try{
            Credential cred = new Credential("AKIDfAPN5WjhOowoPjncARRBernTt2uVpseA", "IJ3WhcHfuud5GBoAFApDKAk4VfaFdkaA");
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("captcha.tencentcloudapi.com");

            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);

            CaptchaClient client = new CaptchaClient(cred, "", clientProfile);


            DescribeCaptchaResultRequest req = new DescribeCaptchaResultRequest();
            req.setCaptchaType(9L);
            req.setTicket(ticket);
            req.setUserIp(userip);
            req.setRandstr(randstr);
            req.setCaptchaAppId(2078609259L);
            req.setAppSecretKey("0dKwks0JJGDvFE8C7XwwSJw**");


            DescribeCaptchaResultResponse resp = client.DescribeCaptchaResult(req);
            return DescribeCaptchaResultResponse.toJsonString(resp);
        } catch (TencentCloudSDKException e) {
            System.out.println(e.toString());
            return e.getMessage();
        }
    }
}
